/**
 * 图形验证码路由
 */

var router = require('express').Router();
const captcha = require('svg-captcha');

router.get('/captcha',async (req,res)=>{
    const cap = captcha.create({
        size: 4, // size of random string
        ignoreChars: '01OoIl', // filter out some characters like 0o1i
        noise: 2, // number of noise lines
        color: true, // characters will have distinct colors instead of grey, true if background option is set
        background: '#f8f8f8' // background color of the svg image
    });
    req.session.captcha = cap.text; // session 存储
    await req.session.save();
    res.type('svg'); // 响应的类型
    res.send(cap.data);
});

module.exports = router;